<template>
	<view class="page flex-col">
		<uni-nav-bar color="white" @clickLeft="back" :fixed="true" :background-color="navColor" status-bar
			left-icon="left" :border="false">
			<view class="top">
				提交策划案
			</view>
		</uni-nav-bar>
		<view class="head"></view>
		<view class="block_1 flex-col">
			<view :class="['text-wrapper_1','flex-col',{can:can}]" @tap="submit">
				<text class="text_3" >提交审核</text>
			</view>
		</view>
		<view class="box_3 flex-col">
			<text class="text_4">{{title}}</text>
			<view class="divide"></view>
			<view class="box_6 flex-row justify-between">
				<text class="text_5">活动开始时间</text>
				<view class="image-text_7 flex-row justify-between">
					<picker class="picker" mode="date" :value="startdate" @change="bindDate1Change">
						<view class="inputitem">
							<text v-if="startdate==null" class="text-group_1">请选择时间</text>
							<text v-else class="text-group_1 int">{{startdate}}</text>
							<image referrerpolicy="no-referrer" src="../../static/icon/right.png" />
						</view>
					</picker>


				</view>
			</view>
			<view class="divide"></view>
			<view class="box_7 flex-row justify-between">
				<text class="text_6">活动结束时间</text>
				<view class="image-text_8 flex-row justify-between">
					<picker class="picker" mode="date" :value="enddate" @change="bindDate2Change">
						<view class="inputitem">
							<text v-if="enddate==null" class="text-group_2">请选择时间</text>
							<text v-else class="text-group_2 int">{{enddate}}</text>
							<image referrerpolicy="no-referrer" src="../../static/icon/right.png" />
						</view>
					</picker>
				</view>
			</view>
			<view class="divide"></view>
			<view class="box_8 flex-row justify-between">
				<text class="text_7">策划案上传</text>
				<view class="image-text_9 flex-row justify-between" @tap="uploadfile">
					<text v-if="!filename" class="text-group_3">请选择pdf文件</text>
					<text v-else class="text-group_3 int filename" >{{filename}}</text>
					
					<image class="thumbnail_15" referrerpolicy="no-referrer" src="../../static/icon/right.png" />
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import helper from "../../utils/helper";
	import { agingApi as agingApi } from "../../utils/api";
	export default {
		data() {
			return {
				id:'',
				title:'',
				navColor: 'transparent',
				constants: {},
				startdate: null,
				enddate: null,
				md5: null,
				filename:"",
				can:false,
				placeholderStyle: "color:#cccccc;font-size:32rpx",
				styles: {
					color: '#383838',
					fontSize: '50rpx'
				}
			};
		},
		onLoad(e){
			
			this.id=e.id
			this.title=e.title
		},
		methods: {
			uploadfile() {
				let that=this
				uni.chooseMessageFile({
					count: 1, //最多可以选择的文件个数，可以 1
					type: 'file', //所选的文件的类型，具体看官方文档
					extension: ['pdf'], //文件类型, '.docx''.doc', 
					success:async (res)=>{
						// console.log('上传', res)
						// // tempFilePath可以作为img标签的src属性显示图片
						const tempFilePaths = res.tempFiles[0].path
						let filename = res.tempFiles[0].name; //用于页面显示的名字

						// console.log(filename)
						// 这一步判断可以省略，如果需求没有格式要求的话
						if (filename.indexOf(".pdf") == -1) {
							that.$toast('暂时仅支持pdf格式的文件')
							return
						} else if (res.tempFiles[0].size > (10 * 1024 *
							1024)) { //这里限制了文件的大小和具体文件类型,如果不限制文件类型则去掉'|| filename.indexOf(".pdf") == -1'
							that.$toast('文件大小不能超过10MB')

						} else {
							
							that.md5 = await helper.uploadFile(tempFilePaths,filename)
							that.filename=filename
							this.iscan()
						}
					},
					fail: (err) => {
						console.log(err, 'err');
						that.$forceUpdate()
					}
				})
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			iscan(){
				if(this.startdate&&this.enddate&&this.filename){
					this.can=true
				}
			},
			bindDate1Change(e) {
				this.startdate = e.detail.value
				this.iscan()
			},
			bindDate2Change(e) {
				this.enddate = e.detail.value
				this.iscan()
			},
			async submit() {
				
					uni.showLoading()
				    var result = await agingApi.submittian({
				        id: this.id,
						startDate:this.startdate,
				        endDate: this.enddate,
				        planningMd5: this.md5,
				    });
				    if (result) {
						
				    
				    }
				uni.hideLoading()
				
				
				uni.navigateTo({
					url: '/pages/submitplan/success'
				})
			}
		},
	};
</script>
<style lang="scss">
	@import '../common/common.scss';
	@import './index.scss';
</style>